﻿@page
@model DotNetStar.TheKing.Web.Pages.Account.RegisterModel
@{
    ViewBag.Title = "快速注册";
}

<div class="row">
    <div class="col-5 border mx-auto pt-3 pb-3">
        <h3>@ViewBag.Title</h3>
        <div class="form-group mt-4">
            <input class="form-control form-control-lg" maxlength="15" placeholder="昵称，长度在2-15个字符" id="UserName" />
        </div>
        <div class="form-group mt-4">
            <input class="form-control form-control-lg" placeholder="手机号码" id="Mobile" />

        </div>
        <div class="form-group mt-4">
            <div class="row">
                <div class="col-6">
                    <input class="form-control form-control-lg" placeholder="验证码" type="text" id="Code" />

                </div>
                <div class="col-6">

                    <button class="btn btn-primary btn-block btn-lg" onclick="sendCode(this, $('#Mobile'), false)" formnovalidate type="button">
                        发送验证码
                    </button>
                </div>
            </div>
        </div>
        <div class="form-group mt-4">
            <button class="btn btn-dark btn-block btn-lg" type="button" onclick="return submit()">立即注册</button>
        </div>
        <div class="mt-3 mb-3">
            <div class="float-left">
                <a asp-page="Login">立即登录</a>
            </div>
            <div class="float-right">
                <a asp-page="FindPwd">找回密码</a>
            </div>
        </div>
    </div>
</div>
@section scripts{
    @Html.Partial("../Shared/_ValidationScripts.cshtml")

    <script type="text/javascript">
        $('footer').addClass('fixed-bottom');
        function submit() {
            var userName = $('#UserName').val();
            var mobile = $('#Mobile').val();
            var code = $('#Code').val();
            if (!userName) {
                bootbox.alert('请输入昵称');
                return false
            }
            if (!mobile) {
                bootbox.alert('请输入手机号');
                return false
            }

            if (!code) {
                bootbox.alert('请输入验证码');
                return false
            }
            $.ajax({
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("XSRF-TOKEN",
                        $('input:hidden[name="__RequestVerificationToken"]').val());
                },
                data: {
                    userName: userName,
                    mobile: mobile,
                    code: code
                },
                url: '/Account/Register',
                type: 'post',
                success: function (data) {
                    location.href = data;
                },
                error: function (data) {
                    bootbox.alert(data.responseText);
                }
            });
        }
    </script>
}